﻿@model Sys_Organization
@{
	ViewBag.Title = (Model.ID > 0 ? "修改" : "新增") + "单位";
}
@section header{
	@*<link href="~/lib/select2/select2.min.css" rel="stylesheet" asp-append-version="true" />*@
	<style>
		.detail-content-info, .detail-content-label {
			padding: 3px;
		}
	</style>
}
@section quickmenu{
	<td style="padding-right: 0px; padding-left: 10px;">
		<span style="cursor: pointer;" title="返回..." @@click="pageBack">
			<i class="icon-reply icon-2x pull-left icon-border crm-bu-style"></i>
		</span>
	</td>
}

<table style="border:0;margin:0;border-spacing:0;width:100%;padding:0 15px 10px 15px;overflow:auto;table-layout:fixed;">
	<tbody>
		<tr>
			<td class="detail-left-td">
				<div class="detail-panel-div">
					<div class="detail-inner">
						<div class="detail-name-div" title="@(Model.ID>0?Model.Name:"新增单位")">
							@(Model.ID > 0 ? Model.Name : "新增单位")
						</div>
					</div>
					<div class="detail-heading">
						相关记录
					</div>
					<div class="detail-inner detail-related">
						<div class="detail-list-div-disabled" v-for="(ritem) in related">
							{{ritem.name}}
						</div>
					</div>
					<div class="detail-exit">&nbsp;</div>
				</div>
			</td>
			<td style="vertical-align:top;" class="detail-content-td">
				<div style="width:100%;margin:0;padding:0;" v-show="viewid=='main'">
					<table style="width:100%;">
						<tr>
							<td style="vertical-align:top;">
								<form id="frmEdit">
									<div class="detail-panel-div" style="position:relative;">
										<table border="0" cellspacing="0" cellpadding="5" style="height:42px;width:100%;">
											<tbody>
												<tr class="detail-content-heading" style="height: 28px;">
													<td colspan="2">
														<b>&nbsp;基本信息&nbsp;</b>
													</td>
												</tr>
												<tr>
													<td colspan="2">
														<table border="0" cellspacing="0" cellpadding="0" style="width:100%;">
															<tr style="height: 25px">
																<td class="detail-content-label label-required" width="20%">
																	单位名称
																</td>
																<td class="detail-content-info" width="30%">
																	<input type="text" class="detailedViewTextBox validate[required]" v-model.trim="model.Name" @@change="handleChangeName">
																</td>
																<td class="detail-content-label" width="20%">
																	拼音助记码
																</td>
																<td class="detail-content-info" width="30%">
																	<input type="text" class="detailedViewTextBox input-sm" v-model.trim="model.PYCode" @@change="handleChangePYCode">
																</td>
															</tr>
															<tr style="height: 25px">
																<td class="detail-content-label">
																	单位类型
																</td>
																<td class="detail-content-info">
																	<select name="Type" v-model="model.Type" class="validate[required]">
																		<option value="">请选择</option>
																		<option :value="c.value" v-for="(c) in types">{{c.text}}</option>
																	</select>
																</td>
																<td class="detail-content-label">
																	关联往来单位
																</td>
																<td class="detail-content-info">
																	<input type="text" class="detailedViewTextBox input-sm" v-model="model.PartnerName" readonly style="cursor:pointer;" onclick="openPopPartner();">
																	<button class="pure-button pure-button-edit pure-icon-bu" style="width: 23px; height: 21px;margin-right:5px;" title="选择" onclick="openPopPartner();return false;">
																		<i class="icon-search"></i>
																	</button>
																	<button class="pure-button pure-button-approve pure-icon-bu" style="width: 23px; height: 21px;" title="清除" onclick="clearPopPartner();return false;">
																		<i class="icon-remove"></i>
																	</button>
																</td>
															</tr>
															<tr style="height: 25px">
																<td class="detail-content-label">
																	所属区域
																</td>
																<td class="detail-content-info">
																	<input type="text" class="detailedViewTextBox input-sm" v-model="model.AreaName" id="AreaID" readonly style="cursor:pointer;width: 80%;" onclick="openArea();">
																	<button class="pure-button pure-button-edit pure-icon-bu" style="width: 23px; height: 21px;margin-right:5px;" title="选择" onclick="openArea();return false;">
																		<i class="icon-search"></i>
																	</button>
																	<button class="pure-button pure-button-approve pure-icon-bu" style="width: 23px; height: 21px;" title="清除" onclick="clearArea();return false;">
																		<i class="icon-remove"></i>
																	</button>
																</td>
																<td class="detail-content-label label-required">
																	单位编码
																</td>
																<td class="detail-content-info">
																	<input type="text" class="detailedViewTextBox input-sm validate[required]" v-model.trim="model.Code">
																	@*@Html.DropDownList("Gender", ViewBag.GenderOptions as IEnumerable<SelectListItem>, "请选择", new { v_model = "model.Gender", @class = "validate[required]" })*@
																</td>
															</tr>
															<tr style="height: 25px">
																<td class="detail-content-label">
																	电话
																</td>
																<td class="detail-content-info">
																	<input type="text" class="detailedViewTextBox input-sm" v-model.trim="model.Phone" />
																</td>
																<td class="detail-content-label">
																	传真
																</td>
																<td class="detail-content-info">
																	<input type="text" class="detailedViewTextBox input-sm" v-model="model.Fax" />
																</td>
															</tr>
															<tr style="height: 25px">
																<td class="detail-content-label">
																	负责人
																</td>
																<td class="detail-content-info">
																	<input type="text" class="detailedViewTextBox input-sm" v-model="model.ChargeMan" />
																</td>
																<td class="detail-content-label">
																	联系电话
																</td>
																<td class="detail-content-info">
																	<input type="text" class="detailedViewTextBox input-sm" v-model.trim="model.ChargeManPhone" />
																</td>
															</tr>
															<tr style="height: 25px">
																<td class="detail-content-label">
																	详细地址
																</td>
																<td class="detail-content-info distpicker" colspan="3">
																	<select class=""></select>
																	<select class=""></select>
																	<select class=""></select>
																	@*<select v-model="model.Town"></select>*@
																	<input type="text" class="detailedViewTextBox" v-model="model.DetailAddress" style="width:30%;vertical-align: top;margin-top: 2px">
																</td>
															</tr>
															<tr>
																<td class="detail-content-label">
																	备注
																</td>
																<td class="detail-content-info" colspan="3">
																	<textarea v-model="model.Comment" style="height:35px;"></textarea>
															</tr>
														</table>
													</td>
												</tr>
												<tr style="height: 38px;">
													<td style="text-align:center;">
														<button class="pure-button pure-button-edit" onclick="$('#frmEdit').submit();return false;" style="margin-right:50px;">
															<i class="icon-check"></i>&nbsp;保存&nbsp;
														</button>
														<button class="pure-button" @@click.prevent='pageBack'>
															<i class="icon-undo"></i>&nbsp;取消&nbsp;
														</button>
													</td>
												</tr>
											</tbody>
										</table>
									</div>
								</form>
							</td>
							<td class="detail-right-td" style="">
								<div class="detail-panel-div">
									<div class="detail-inner">
										<table border="0" cellpadding="5" cellspacing="0" class="module-tool-tab" style="width:100%;">
											<tr>
												<td align="left" class="genHeaderSmall" style="padding:5px;">操作</td>
											</tr>
											<tr>
												<td align="left" style="padding:5px;">
													<img src="~/theme/img/pointer.gif" hspace="5" />
													<a href="javascript:viewDetailLog(@((int)ST.Buz.Base.Enums.TableCode.Sys_Organization),@(Model.ID));" class="webMnu">修改日志</a>
												</td>
											</tr>
										</table>
									</div>
								</div>
							</td>
						</tr>
					</table>
				</div>
			</td>
		</tr>
	</tbody>
</table>
@section footer{
	<script src="~/js/related/sys_attachment.js" asp-append-version="true"></script>
	<script src="~/js/pinyin.js" asp-append-version="true"></script>
	@*日期必须开始*@
	@*<script src="~/lib/laydate/laydate.js" asp-append-version="true"></script>*@
	@*日期必须结束*@
	<script src="~/lib/distpicker.js" asp-append-version="true"></script>
	@*<script src="~/lib/select2/select2.min.js" asp-append-version="true"></script>*@
	@*验证开始*@
	<script src="~/lib/validationEngine/jquery.validationEngine.min.js" asp-append-version="true"></script>
	<script src="~/lib/validationEngine/jquery.validationEngine-zh_CN.js" asp-append-version="true"></script>
	<link href="~/lib/validationEngine/validationEngine.jquery.css" rel="stylesheet" asp-append-version="true" />
	@*验证结束*@
	@*列表相关开始*@
	<script type="text/javascript">
		var pageEnumData = {
			state: @(Json.Serialize(ViewBag.StateOptions)),
			types: @(Json.Serialize(ViewBag.TypeOptions)),
		};
		var modelJson=@(Html.Raw(Newtonsoft.Json.JsonConvert.SerializeObject(Model,new Newtonsoft.Json.JsonSerializerSettings()
				   {
				   DateFormatString = "yyyy-MM-dd HH:mm:ss"
					})));
		var modelData = $.extend(modelJson, {
		});
		var pageData = {
			hideBreadcrumb: false,
			serviceCode: '@(ViewBag.ServiceCode)',
			global: globalData,
			viewid: 'main',
			related: @(Json.Serialize(ViewBag.RelatedModules)),
			types: pageEnumData.types,
			model:modelData
		};

		var pageApp = new Vue({
			el: '#app',
			data: pageData,
			created: function () {
			},
			mounted: function () {
			},
			methods: {
				pageBack: function () {
					//history.go(-1);
					if (@(Model.ID>0?"true":"false")) {
						history.back();
					} else {
						location.href = '@(Url.Action("List", "Sys_Organization"))?nc=' + new Date().getTime();
					}
				},
				pageSave: function () {
					utils.ajaxPost('@(Url.Action("Save", "Sys_Organization"))', this.model, function (resp) {
						console.log(resp.data);
						utils.success("保存成功");
						location.href = '@(Url.Action("ViewDetail", "Sys_Organization",new {id="" }))/'+resp.data+'?nc=' + new Date().getTime();
					}, function (msg) {
						utils.alert(msg);
					});
				},
				handleChangeName: function () {
					modelData.PYCode = utils.pinyin.getFirstLetter(modelData.Name).substr(0,10);
				},
				handleChangePYCode: function () {
					if (!!modelData.PYCode) {
						modelData.PYCode = modelData.PYCode.toUpperCase().substr(0,10);
					}
				},
				relatedSysAttachmentChange: function (vid, e) {
					switch (e.action) {
						case "total":
							{
								this.related = this.related.map(function (item) {
									if (item.id == vid) {
										return Object.assign({}, item, { count: e.data });
									} else {
										return item;
									}
								});
							}
							break;
					}
				},
				changeView: function (vid) {
					this.viewid = vid;
					this.$refs[vid]&&this.$refs[vid].reload();
				},
				resetView: function () {
					this.viewid = 'main';
				}
			},
			computed: {
				currentM: function () {
					var currentM = null;
					var i;
					var j;
					for (i = 0; i < this.global.modules.length; i++) {
						for (j = 0; j < this.global.modules[i].Services.length; j++) {
							if (this.serviceCode == this.global.modules[i].Services[j].Code) {
								currentM = this.global.modules[i];
								break;
							}
						}
					}
					return currentM;
				},
				currentS: function () {
					var currentS = null;
					var i;
					var j;
					for (i = 0; i < this.global.modules.length; i++) {
						for (j = 0; j < this.global.modules[i].Services.length; j++) {
							if (this.serviceCode == this.global.modules[i].Services[j].Code) {
								currentS = this.global.modules[i].Services[j];
								break;
							}
						}
					}
					return currentS;
				}
			}
		});

		$(document).ready(function () {
			$("#frmEdit").keypress(function (e) {
				if (e.keyCode == 13) {
					return false;
				}
			}).validationEngine({
				scroll: false,
				validateNonVisibleFields: false,
				autoHidePrompt: true,
				showOneMessage: true,
				ajaxFormValidationMethod: 'post',
				onValidationComplete: function (form, status) {
					if (!status) {
						return;
					}
					var $districts = $(".distpicker select");
					modelData.Province = $districts[0].value;
					modelData.City = $districts[1].value;
					modelData.District = $districts[2].value;
					pageApp.pageSave();
				}
			});

			$(".distpicker").distpicker({
				province: modelData.Province || '',
				city: modelData.City || '',
				district: modelData.District || ''
			});
		});

		function openArea() {
			var $input = $('#AreaID');
			var srcPos = $input.offset();
			layer.open({
				title: false,
				type: 2,
				area: ['400px', '450px'],
				fixed: true, //不固定
				closeBtn:1,
				icon: 2,   //加载的icon类型
				offset: [(srcPos.top + $input.height() + 8) + "px", srcPos.left + "px"],
				content: '@(Url.Action("PopList","Sys_Area"))?callback=popAreaCallback',
			});
		}

		function popAreaCallback(ret,popIndex) {
			if (!ret || ret.id == '' || ret.id == '0' || ret.id == '-1') {
				return;
			}
			var names = ret.name;
			var node = ret.getParentNode();
			while (node) {
				names = node.id != '' && node.id != '0' && node.id != '-1'?node.name+'/'+names:names;
				node = node.getParentNode();
			}
			modelData.AreaID = ret.id;
			modelData.AreaName = names;
			modelData.AreaCode = ret.code;
			utils.ajaxPost('@(Url.Action("GenCode", "Sys_Organization"))', { areacode: modelData.AreaCode }, function (resp) {
				modelData.Code = resp.data;
			});
			layer.close(popIndex);
		}

		function clearArea() {
			modelData.AreaID = 0;
			modelData.AreaName = "";
			modelData.AreaCode = "";
		}

		function openPopPartner() {
			utils.layerFull('@(Url.Action("PopList", "IMS_Partner"))?type=@((int)PartnerType.供应商)&callback=popPartnerCallback', "选择供应商", "Partner");
		}

		function popPartnerCallback(index, ret) {
			if (!ret) {
				return;
			}
			pageApp.model = Object.assign({}, pageApp.model, {
				PartnerID: ret.ID,
				PartnerName: ret.Name
			});
		}

		function clearPopPartner() {
			pageApp.model = Object.assign({}, pageApp.model, {
				PartnerID: 0,
				PartnerName: ""
			});
		}
	</script>
	@*列表相关结束*@
}